//
//  String+Extension.swift
//  SwiftWeibo
//
//  Created by Lausen on 2017/5/15.
//  Copyright © 2017年 id. All rights reserved.
//

import Foundation

extension String{
    
    func lau_href() -> (link: String,text: String)? {
        
        //1:匹配模式
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        
        //2:创建正则表达式并且匹配第一项
        guard let regx = try? NSRegularExpression(pattern: pattern, options: []),
              let result = regx.firstMatch(in: self, options: [], range: NSRange(location: 0, length: characters.count))
            else{
            
            return ("","")
        }
        
        //3:获取结果
        let link = (self as NSString).substring(with: result.rangeAt(1))
        let text = (self as NSString).substring(with: result.rangeAt(2))
        
        return (link,text)
    }
}
